import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: "/index"
    },
    {
      path: '/Index',
      name: 'Index',
      redirect: '/home',
      component: () => import('./views/Index.vue'),
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('./views/Home.vue')
        },
        {
          path: '/infoShow',
          name: 'infoShow',
          component: () => import('./views/InfoShow.vue')
        },
        {
          path: '/fundlist',
          name: 'fundlist',
          component: () => import('./views/Fundlist.vue')
        },
      ]
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('./views/Register.vue')
    },

    {
      path: "*",
      component: () => import('./views/404.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('./views/Login.vue')
    },
    {
      path: '/404',
      name: '404',
      component: () => import('./views/404.vue')
    },
  ]
})
// 路由守卫判断登录页面
router.beforeEach((to, from, next) => {
  const isLogin = sessionStorage.getItem(`eleToken`) ? true : false;
  if (to.name == "login" || to.name == "register") {
    next()
  } else {
    isLogin ? next() : next("/login")
  }
})
export default router;
